﻿using CommonTools;
using YukariToolBox.LightLog;
using LogLevel = YukariToolBox.LightLog.LogLevel;

namespace MidJourneyApi.Middleware;

/// <summary>
/// log设置
/// </summary>
public class LogMiddleware
{
    private readonly RequestDelegate next;

    public LogMiddleware(RequestDelegate next)
    {
        this.next = next;
    }

    public async Task Invoke(HttpContext context)
    {
        string logInfo = AppConfigurationServices.Configuration["DiscordSetting:LOG_LEVEL"];
        if (!string.IsNullOrEmpty(logInfo))
        {
            if (Enum.TryParse(logInfo, out LogLevel level))
            {
                //设置log等级
                Log.LogConfiguration.EnableConsoleOutput().SetLogLevel(level);
            }
        }
        await next(context);
    }
}